<template>
	<view class="deep">
		<scroll-view scroll-y="true" :style="{'height':scrollHeight}">
			<view class="mt-5" v-if="u_loadmore">
				<u-loadmore status="loading" icon-type="circle" />
			</view>
			<view v-else>
				<!-- 店铺推荐 -->
				<view class="m-2 bg-white rounded-20 py-2 pl-3">
					<view class="font-md">加入推荐</view>
					<view class="py-3 d-flex">
						<view class="flex-1">
							<u-checkbox-group>
								<u-checkbox @change="cakes" v-model="editList.store_hot" shape="circle" icon-size="30"  size="40" active-color="#F24F4A"
								>热销</u-checkbox>
							</u-checkbox-group>
						</view>
						<view class="flex-1">
							<u-checkbox-group>
								<u-checkbox @change="prod" v-model="editList.store_new"  shape="circle" icon-size="30"  size="40" active-color="#F24F4A"
								>新品</u-checkbox>
							</u-checkbox-group>
						</view>
						<view class="flex-1">
							<u-checkbox-group>
								<u-checkbox @change="products" v-model="editList.store_best"  shape="circle" icon-size="30"  size="40" active-color="#F24F4A"
								>精品</u-checkbox>
							</u-checkbox-group>
						</view>
					</view>
				</view>
				<!-- 商家服务 -->
				<view class="m-2 bg-white rounded-20 py-2 pl-3">
					<view class="font-md">退款标识</view>
					<view class="py-3 d-flex ">
						<view class="">
							<u-checkbox-group>
								<u-checkbox v-model="editList.return_mark"  shape="circle" icon-size="30"  size="40" active-color="#F24F4A"
								@change="return_mark">仅退款</u-checkbox>
							</u-checkbox-group>
						</view>
					</view>
				</view>
				
				<view class="rounded-20 m-2 pl-3  bg-white">
					<view class="d-flex border-bottom j-sb pr-2 py-3 a-center clazz" @click="goodsPrice">
						<view class="">商品价格</view>
						<view class="d-flex j-center a-center">
							<text class="text-light-muted mr-1">去设置</text>
							<u-icon name="arrow-right" color="#909399" size="30"></u-icon>
						</view>
					</view>
					<view class="d-flex j-sb pr-2 py-3 a-center clazz">
						<view class="">商品品牌</view>
						<view class="d-flex j-center a-center">
							<text class="text-light-muted mr-1">去设置</text>
							<u-icon name="arrow-right" color="#909399" size="30"></u-icon>
						</view>
					</view>			
				</view>
				
				
				<view class="rounded-20 m-2 pl-3  bg-white " >
					<view class="d-flex j-sb border-bottom pr-2 py-3 a-center clazz" @click="goodsAlbum">
						<view class="">商品相册</view>
						<view class="d-flex j-center a-center">
							<text class="text-light-muted mr-1">去添加</text>
							<u-icon name="arrow-right" color="#909399" size="30"></u-icon>
						</view>
					</view>
					<view class="d-flex j-sb pr-2 py-3 a-center clazz" @click="goods_desc">
						<view class="">商品描述</view>
						<view class="d-flex j-center a-center">
							<text class="text-light-muted mr-1">去添加</text>
							<u-icon name="arrow-right" color="#909399" size="30"></u-icon>
						</view>
					</view>			
				</view>
				
				<view class="rounded-20 m-2 pl-3 bg-white clazz" >
					<view class="d-flex j-sb pr-2 py-3 a-center clazz" @click="goodsAss">
						<view class="">关联商品</view>
						<view class="d-flex j-center a-center">
							<text class="text-light-muted mr-1">{{editList.has_linked_goods=='yes'?'已关联':'去关联'}}</text>
							<u-icon name="arrow-right" color="#909399" size="30"></u-icon>
						</view>
					</view>			
				</view>
				<view class="rounded-20 m-2 pl-3 bg-white clazz" >
					<view class="d-flex j-sb pr-2 py-3 a-center clazz">
						<view class="">普通商品</view>
						<view class="d-flex j-center a-center">
							<u-switch @change="ordinary" v-model="editList.is_alone_sale" size="43"></u-switch>
						</view>
					</view>			
				</view>
				<view class="py-1 text-center font-sm">
					开启则此为商品作为普通商品销售,关闭则此商品只能作为赠品或配件销售
				</view>
				
				<view class="rounded-20 m-2 pl-3 bg-white clazz" >
					<view class="d-flex j-sb pr-2 py-3 a-center clazz">
						<view class="">上架商品</view>
						<view class="d-flex j-center a-center">
							<u-switch @change="ordinary" v-model="editList.is_alone_sale" size="43"></u-switch>
						</view>
					</view>			
				</view>
				<view class="py-1 text-center font-sm">
					开启则此商品将在前端页面展示，关闭则不显示
				</view>
			</view>
		</scroll-view>
		<view class="footer"></view>
		<view class="bg-white release py-2 w-100 position-fixed bottom-0">
			<button type="warn" :disabled="isDisable" @click="release_sub">提交</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				defaltImage:'../../static/images/goods/icon_default_image.png',
				editList:'', // 详情数据 
				goods_id:'' ,// 商品id标识,
				service_show:false, // 包退服务
				product_show:false, // 正品保证
				dispatching_show:false, // 闪送配送
				isDisable:false,
				scrollHeight:0, // 屏幕高度
				u_loadmore:true, // 加载中
			}
		},
		onReady() {
			let _this=this
			uni.getSystemInfo({
				success(resu) {
					const query = uni.createSelectorQuery()
					query.select('.footer').boundingClientRect()
					console.log(resu)
					query.exec(function(res) {
						_this.scrollHeight = resu.windowHeight - res[0].bottom+ 'px';
					})
				}
			})
		},
		methods: {
			// 商品价格
			goodsPrice(){
				uni.navigateTo({
					url:'/pages/goods-edit-expert/goods-edit-expert?goods_id='+this.goods_id
				})
			},
			// 商品规格
			goodsSpec(){
				uni.navigateTo({
					url:'/pages/goods-edit-spec/goods-edit-spec?goods_id='+this.goods_id
				})
			},
			// 商品相册
			goodsAlbum(){
				uni.navigateTo({
					url:'/pages/goods-edit-album/goods-edit-album?goods_id='+this.goods_id
				})
			},
			// 商品视频
			goods_video(){
				uni.navigateTo({
					url:'/pages/goods-video/goods-video?goods_id='+this.goods_id
				})
			},
			// 关联商品
			goodsAss(){
				uni.setStorageSync("goods_id",JSON.stringify(this.goods_id))
				uni.navigateTo({
					url:`/pages/goods-edit-ass/goods-edit-ass?goods_id=${this.goods_id}&goods_name=添加&next_name=下一步`
				})	
			},
			// 图文描述
			goods_desc(){
				uni.navigateTo({
					url:'/pages/goods-edit-desc/goods-edit-desc?goods_id='+this.goods_id
				})
			},
			// 热销
			cakes(e){
				this.$H.post("admin/goods/toggle/suggest",{id:this.goods_id,type:'hot',is_suggest:!this.editList.store_hot}).then(res=>{
					console.log(res,this.editList.store_hot)
				})
			},
			// 新品
			prod(e){
				this.$H.post("admin/goods/toggle/suggest",{id:this.goods_id,type:'new',is_suggest:!this.editList.store_new}).then(res=>{
					console.log(res,this.editList.store_new)
				})
			},
			// 精品
			products(e){
				this.$H.post("admin/goods/toggle/suggest",{id:this.goods_id,type:'best',is_suggest:!this.editList.store_best}).then(res=>{
					console.log(res,this.editList.store_best)
				})
			},
			
			// 退货标识
			return_mark(e){
				// this.$H.post("admin/merchant/goods/goodsservice/update",{goods_id:this.goods_id,type:'return',is_support:!this.editList.is_return}).then(res=>{
				// 	console.log(res,this.editList.is_return)
				// })
			},
			// 普通商品
			ordinary(){
				if(this.editList.is_alone_sale){
					this.$H.post("admin/goods/toggle/gifts",{id:this.goods_id,is_gift:0}).then(res=>{
						console.log(res)
					})
				}else{
					this.$H.post("admin/goods/toggle/gifts",{id:this.goods_id,is_gift:1}).then(res=>{
						console.log(res)
					})
				}
				
			},
			// 发布成功
			release_sub(){
				uni.redirectTo({
					url:`/pages/goods-release/goods-release?goods_id=${this.goods_id}&virtual=虚拟`
				})
				this.isDisable=true   //点击一次时隔两秒后才能再次点击
			}
		},
		onLoad(e) {
			let arrname="发布成功"
			var globalData = getApp().globalData.release; //获取全局变量
			getApp().globalData.release= arrname; //修改全局变量
			this.goods_id=e.goods_id
			this.$H.post("v2/store/goods/detail",{goods_id:e.goods_id}).then(res=>{
				this.editList=res.data
				this.u_loadmore=false 
			})
		},
		onShow() {
			this.$H.post("v2/store/goods/detail",{goods_id:this.goods_id}).then(res=>{
				this.editList=res.data
			})
		},
	}
</script>

<style>
	.store{
		color: #F84B4F;
		padding: 10upx 20upx;
		background: linear-gradient(to right,#FEDFE4,#FFE7E3);
		border-radius: 50upx;
	}
	.deep /deep/ .u-switch{
		font-size: 40upx;
		border: #0000FF;
	}
	.deep /deep/ .u-switch__node{
		background-color: #000000;
		width: 40upx;
		height: 40upx;
	}
	.release{
		z-index: 111;
	}
	.release /deep/ button{
		width: 85%;
		border-radius: 50upx;
		background: linear-gradient(to right,#F31E3E,#FB4F37);
		z-index: 1111;
	}
	.footer{
		height: 132upx; 
	}
</style>
